package com.entertainment.ticketing.repository;

import com.entertainment.ticketing.entity.UserInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Optional;

public interface UserInfoRepository extends JpaRepository<UserInfo, Long> {
    Optional<UserInfo> findByUsername(String username);
    Optional<UserInfo> findByEmail(String email);

    @Query("select u from UserInfo u where (:keyword is null or lower(u.username) like lower(concat('%', :keyword, '%')) or lower(u.email) like lower(concat('%', :keyword, '%')) or lower(u.phone) like lower(concat('%', :keyword, '%')))")
    Page<UserInfo> searchByKeyword(String keyword, Pageable pageable);
}